<?php
$key_word = "出国留学";
$key_word = trim(urlencode($key_word));
$fp = fopen("url.txt", 'w');
for ($i = 6; $i < 80; $i++) {
	$ali_url="http://www.baidu.com/s?wd=$key_word&pn=".$i."0&usm=2";
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $ali_url);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$file = curl_exec($ch);
	$pattern = "/http:\/\/www..*.com/";
	preg_match_all($pattern, $file, $matches);
	foreach ($matches[0] as $url){
		if (!strpos($url, "baidu")) {
			echo $url."\n";
			fwrite($fp, $url."\n");
		}

	}
	curl_close($ch);
}




fclose($fp);
?>